package com.naishuo.bigevent.controller.user;


import com.naishuo.bigevent.pojo.Category;
import com.naishuo.bigevent.pojo.Result;
import com.naishuo.bigevent.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping//新增分类
    public Result addcategory(@RequestBody Category category)
    {
        categoryService.addcategory(category);
        return Result.success();

    }


    @GetMapping()//获取所有分类
    public Result<List<Category>> findAll()
    {
        System.out.println("categoryService.findAll() = " + categoryService.findAll());
        return Result.success(categoryService.findAll());
    }

    @GetMapping("/detail")//获取分类详情
    public Result<List<Category>> findAllByUserId(Integer id)
    {

        return Result.success(categoryService.findAllByUserId(id));
    }


    @PutMapping()//修改分类
    public Result updateCategory(@RequestBody Category category)
    {
        categoryService.updateCategory(category);
        return Result.success();
    }


    @DeleteMapping()//删除分类
    public Result deleteCategory(Integer id)
    {
        categoryService.deleteCategory(id);
        return Result.success();
    }

//    @DeleteMapping("/{id}")//删除分类
//    public Result deleteCategory(@PathVariable Integer id)
//    {
//        categoryService.deleteCategory(id);
//        return Result.success();
//    }


}
